This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library('quantmod') | |
#loadSymbols of the stock codes you are interested in | |
loadSymbols(c('K17.SI','BN4.SI')) | |
#retrieves the values for a single date | |
BN4.SI['2013-01-25'] | |
#K17.SI['2013-03-04'] | |
#Convert the matrix retrieved as a data.frame for easier data usage |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Sample Contract Value | |
vol=1000 | |
price=10 | |
volprice=vol*price | |
def commSCB(volprice): | |
"SCB commission is fixed 0.2%" | |
brokerage=volprice*0.2/100 | |
clearingfee=0.04/100*volprice | |
#no SGX trading fee |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
"""simple python script to join every 4 lines into one from a plain text file""" | |
data = open("SCBtransactions2013-03-19.orig.csv").readlines() | |
data = [ i.strip() for i in data ] #get rid of newlines | |
data = [ i.replace("\t \t","\t") for i in data ] #get rid of double tabs | |
data = [ i.replace("SGD","") for i in data ] #get rid of SGD | |
fourlines = range(0,len(data),4) | |
for num,line in enumerate(data): | |
if num in fourlines: | |
print ' '.join(data[num:num+4]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Create Table "main"."transactions" | |
CREATE TABLE IF NOT EXISTS "main"."transactions" ("tid" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL , | |
"stkcode" TEXT NOT NULL , | |
"stkname" TEXT, "qty" INTEGER NOT NULL , | |
"broker" TEXT NOT NULL , | |
"price" REAL NOT NULL , | |
"targetprice" REAL, | |
"stoploss" REAL, | |
"longshort" TEXT NOT NULL , | |
"date" TEXT NOT NULL , |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import plotly | |
from plotly.tools import FigureFactory as FF | |
import pandas as pd | |
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/gantt_example.csv') | |
fig = FF.create_gantt(df, colors=['#333F44', '#93e4c1'], index_col='Complete', show_colorbar=True, | |
bar_width=0.2, showgrid_x=True, showgrid_y=True) | |
plotly.offline.plot(fig, filename='gantt-use-a-pandas-dataframe') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rsync -ahP --times --owner --group /mnt/external/exportedReports/Auto_user_S5-00333-1 /media/USB |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The following tricks I find pretty useful in my daily Python work. I also added a few I stumbled upon lately. | |
1. Use collections | |
This really makes your code more elegant and less verbose, a few examples I absorbed this week: | |
Named tuples: | |
>>> Point = collections.namedtuple('Point', ['x', 'y']) | |
>>> p = Point(x=1.0, y=2.0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
samtools view -b -f 4 $1 > $1.unmapped.bam | |
samtools index $1.unmapped.bam | |
java -Xmx8g -jar /opt/picard/picard-tools-current/picard.jar SamToFastq I=$1.unmapped.bam F=$1.unmapped.bam.fastq | |
/home/ionadmin/bin/bbmap/reformat.sh in=$1.unmapped.bam.fastq out=$1.unmapped.bam.fastq.fasta | |
gzip $1.unmapped.bam.fastq.fasta |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
~/bin/kraken2/kraken2 --db ~/k2_standard_16gb_20210517 --use-names --gzip-compressed $1 --output $1.kraken --report $1.kraken.report | |
cut -f2,3 $1.kraken > $1.kraken.kronainput | |
ktImportTaxonomy -tax /home/kev/Krona-master/KronaTools/taxonomy $1.kraken.kronainput -o $1.kraken.kronainput.html |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def read_date(date): | |
if isinstance(date, int): | |
return pd.to_datetime(date,unit='D', origin='1899-12-30') | |
#return xlrd.xldate.xldate_as_datetime(date, 0) | |
else: | |
return(pd.to_datetime(date)) | |
print("Converting 42985 to") | |
print(read_date(42985 )) |
OlderNewer