-
Notifications
You must be signed in to change notification settings - Fork 33
/
databasefxrates.py
45 lines (30 loc) · 1.16 KB
/
databasefxrates.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"""
Python UK trading tax calculator
Copyright (C) 2015 Robert Carver
You may copy, modify and redistribute this file as allowed in the license agreement
but you must retain this header
See README.txt
"""
"""
This code reads my own data base of FX prices
If you have a database of FX prices then replace the code here, keeping the same function name get_fx_data
"""
import datetime
import numpy as np
import sqlite3
import pandas as pd
def get_fx_data(currency):
ans=_get_fx_prices(currency)
getdollars=_get_fx_prices("GBP").reindex(ans.index, method="ffill")
ans=ans/getdollars
return ans
def _get_fx_prices(currency):
if currency=="USD":
date_range = pd.date_range(datetime.datetime(1970,1,1), datetime.datetime.now())
return pd.DataFrame(
[1.0]*len(date_range), index=date_range)
ans =pd.read_csv("/home/rob/pysystemtrade/data/futures/fx_prices_csv/%sUSD.csv" % currency)
ans_index = ans.DATETIME
ans_index = pd.to_datetime(ans_index, format="%Y-%m-%d %H:%M:%S").values
pd_data = pd.DataFrame(list(ans.PRICE.values), index = ans_index)
return pd_data