-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
46 lines (37 loc) · 1.78 KB
/
main.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
45
46
from OpenFintech import *
import pandas as pd
# Example of how to use the OpenFintech library
# Initialize the API wrapper
apiKey = "demo"
data_acq = DataAcquisition(apiKey)
# Request data from the API
ticker_symbol = 'IBM'
timeframe = 'daily' # options: 'daily' or {time}min, e.g. '1min', '5min', '15min', '30min', '60min
tickerData = data_acq.requestDataFromAPI(ticker_symbol, timeframe)
# Convert the data to a FinancialInstrument
ticker_finInst = data_acq.convertDataToFinancialInstrument(tickerData)
# Run calculations on the FinancialInstrument
shortMA = EMA(candle_container = ticker_finInst.candle_container, periodLength = 5)
longMA = SMA(candle_container = ticker_finInst.candle_container, periodLength = 10)
shortMA.runCalcOnCandleContainer()
longMA.runCalcOnCandleContainer()
# Run an algorithm on the FinancialInstrument
tr_algo = TrendFollowing()
tr_backtest_data = tr_algo.runAlgorithmOnCandleContainer(
candle_container = ticker_finInst.candle_container,
short_ma = shortMA,
long_ma = longMA,
stop_loss = 0.05,
take_profit = 0.1,
assets = 10000
)
mr_algo = MeanReversion()
mr_backtest_data = mr_algo.runAlgorithmOnCandleContainer(
candle_container = ticker_finInst.candle_container,
short_ma = shortMA,
long_ma = longMA,
stop_loss = 0.05,
take_profit = 0.1,
assets = 10000
)
print(mr_backtest_data)