指定

import pandas as pd
import numpy as np

def generate_signals(data):
    signals = pd.DataFrame(index=data.index)
    signals['price'] = data['Close']
    
    # Calculate moving averages
    signals['short_ma'] = data['Close'].rolling(window=20, min_periods=1).mean()
    signals['long_ma'] = data['Close'].rolling(window=50, min_periods=1).mean()
    
    # Generate buy signals
    signals['buy_signal'] = np.where(signals['short_ma'] > signals['long_ma'], 1, 0)
    
    # Generate sell signals
    signals['sell_signal'] = np.where(signals['short_ma'] < signals['long_ma'], -1, 0)
    
    return signals

def backtest_strategy(signals, initial_capital=10000):
    positions = pd.DataFrame(index=signals.index).fillna(0.0)
    positions['asset'] = 1000 * signals['buy_signal'] + -1000 * signals['sell_signal']
    
    # Calculate portfolio value
    portfolio = positions.multiply(signals['price'], axis=0)
    pos_diff = positions.diff()
    portfolio['holdings'] = (positions.multiply(signals['price'], axis=0)).sum(axis=1)
    portfolio['cash'] = initial_capital - (pos_diff.multiply(signals['price'], axis=0)).sum(axis=1).cumsum()
    portfolio['total'] = portfolio['cash'] + portfolio['holdings']
    portfolio['returns'] = portfolio['total'].pct_change()
    
    return portfolio

# Example usage:
# Assuming 'data' is a DataFrame containing historical price data with 'Date' as index and 'Close' as a column
# signals = generate_signals(data)
# portfolio = backtest_strategy(signals)
# print(portfolio.tail())

応答済み

1
開発者 1
評価
(167)
プロジェクト
215
57%
仲裁
8
25% / 25%
期限切れ
7
3%
仕事中
2
開発者 2
評価
(230)
プロジェクト
431
27%
仲裁
123
21% / 55%
期限切れ
96
22%
仕事中
3
開発者 3
評価
(250)
プロジェクト
399
38%
仲裁
82
41% / 20%
期限切れ
69
17%
多忙
類似した注文
"Hi there! I'm in search of a developer proficient in integrating TradingView signals with cTrader. If you have experience in API integration and are well-versed in both cTrader and TradingView, I'd love to hear from you. This project entails linking the platforms to detect signals and execute actions in cTrader. Eagerly anticipating collaboration with someone capable of assisting with the project. Thank you!"
"I'm on the lookout for a proficient developer to help bring my unique NT8 strategy to fruition. Your expertise will be instrumental in driving this project forward. Are you interested in forming a dynamic partnership to achieve our goals? Let's dive into the details together. Thank you!"
"I'm seeking a skilled developer to collaborate on bringing my custom NT8 strategy to life. Your expertise will play a pivotal role in ensuring the success of this project. Are you open to joining forces for a mutually beneficial partnership? Let's connect and delve into the specifics together. Thank you!"
I am looking for a coder to code my custom Ninjatrader 8. your experise is needed in this project, let's connect to execute the project. you can kindly contact me and let start the project without any further delay much appreciation
"I'm looking for a talented developer to help implement my custom NT8 strategy. Your expertise is key to the project's success. Are you interested in teaming up for a productive partnership? Let's discuss the details together. Thank you!"
"I'm on the lookout for a proficient developer to help actualize my tailored NT8 strategy. Your mastery in this field is pivotal for the project's success. Would you be open to partnering for a mutually beneficial collaboration? Let's explore the details together. Thank you for considering!"
"I'm in search of a skilled developer to bring my customized NT8 strategy to life. Your expertise is crucial for the success of this project. Would you be interested in joining forces for a fruitful collaboration? Let's connect to delve into the specifics together. Much appreciated!"
i want close on reserve signal, auto lots, time fiter , TP SL TS ETC. I GET PAID ON THE 12TH, SO I WOULD LIKE A DEMO UNTIL 12/05/24 TO TEST IM WILL TOO PAY 60 USD FOR THE LONG WAIT
MT5 Broker Research 50 - 100 USD
Looking For Someone With Good knowledge of Available MT5 Brokers to help with MT5 Demo Account research. The Objective of the research is to gather data on trading environment in each MT5 demo account by downloading the demo and accessing such factors as. 1 ) Number Of Trading Sectors Covered, example , Forex, Futures, Commodities, Stocks and Global Region Of Stocks etc 2) Total Number Of Symbols In Market Watch 3)
Crpyto Indicators 75 - 100 USD
2 Indicators: One for BTC/USD and one for ETH/USD Create indicators which plot the MVRV of Bitcoin and Ethereum as a line, standardized by a Z Score Essentially Zscore = ( MC - MCRealized ) / STD ( MC(number of bars ) Indicators should work on the daily timeframe at a minimum, and smaller ones if possible. Indicators should be able to work with future data as well, meaning it can download what's necessary to then

プロジェクト情報

予算
30 - 50 USD
締め切り
最低 1 最高 14 日

依頼者

出された注文1
裁定取引数0