Backtesting Saves Candlestick to Local CSV
Python strategy by 小草.
PythonOther
The original spec has no written description. Read the source below.
Source Python
'''
/*backtest
start: 2017-10-01
end: 2017-11-16
period: 1440
periodBase: 15
mode: 0
*/
'''
#Requiredpandasof the library, and only with my own hosted backtesting can it be saved locally
#import numpy as np
import pandas as pd
#Save path
path = 'C:\\Users\\Public\\Documents\\'
def main():
df=pd.DataFrame()
while True:
records = _C(exchange.GetRecords)
df_new = pd.DataFrame(records) #holdrecordsConvert todataframe
df_new['Time'] = pd.to_datetime(df_new['Time'],unit='ms')+pd.Timedelta('8 h')
df_new.index = df_new['Time']
if df.empty or df_new['Time'].min() >= df['Time'].max():
df=df.combine_first(df_new)
Log(df['Time'].max())
#Confirm the last time for saving data
if df_new['Time'].max() == pd.Timestamp('2017-11-15 23:45:00'):
Log('Save data')
df=df.combine_first(df_new)
df.to_csv(path+'records15.csv',index=False)
break
#Sleep time is the selected period
Sleep(15*60*1000)
Published by 小草 on the FMZ strategy square · last modified 2017-12-15. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.
Build this with AgenKit
A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Backtesting-Saves-Candlestick-to-Local-CSV.md- npx agenkit install engineering-kit in your project
- Paste the command into your agent and approve each phase
- Get tests, backtest, risk controls and a paper-trading switch
Understand it first
Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.
Related specs
- Dynamic Balancing Strategy Python VersionPython · Other
- Exchange Wash Trading and Mutual BrushingPython · Other
- Leek Protection Program Tang Anqi Channel Position Balancing StrategyPython · Other
- Paul The Gambler Lévy Gold EditionPython · Other
- Porting OKCoin Leek Harvester Multi Variety Version Annotated Python VersionPython · Other
- Python Example Using asyncio http to Obtain Market DataPython · Other