forked from ztuntrade/Quant-Template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathback_test.py
70 lines (49 loc) · 1.62 KB
/
back_test.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
"""
All modules and functions required for back_test should be added in requirements.txt.
"""
import pandas as pd
from untrade.client import Client
# ALL your imports here
def process_data(data):
"""
Process the input data and return a dataframe with all the necessary indicators and data for making signals.
Parameters:
data (pandas.DataFrame): The input data to be processed.
Returns:
pandas.DataFrame: The processed dataframe with all the necessary indicators and data.
"""
return data
# -------STRATEGY LOGIC--------#
def strat(data):
"""
Create a strategy based on indicators or other factors.
Parameters:
- data: DataFrame
The input data containing the necessary columns for strategy creation.
Returns:
- DataFrame
The modified input data with an additional 'signal' column representing the strategy signals.
"""
return data
def perform_backtest(csv_file_path):
client = Client()
result = client.backtest(
jupyter_id="Your User", # the one you use to login to jupyter.untrade.io
file_path=csv_file_path,
leverage=1, # Adjust leverage as needed
)
return result
def main():
data = pd.read_csv("data/2018-22/YOUR CSV")
processed_data = process_data(data)
result_data = strat(processed_data)
csv_file_path = "results.csv"
result_data.to_csv(csv_file_path, index=False)
backtest_result = perform_backtest(csv_file_path)
print(backtest_result)
last_value = None
for value in backtest_result:
last_value = value
print(last_value)
if __name__ == "__main__":
main()