Calculating Equity Curve with Deducted Overnight Fees

21 Oct 2022
0 comment
0 attachment

This ProBuilder code snippet demonstrates how to calculate an equity curve for a trading strategy, taking into account the deduction of overnight fees. The equity curve represents the value of a trading account over time, providing insights into the performance of the trading strategy.


// Initial account balance
account_balance = 10000

// Simulated daily returns
daily_returns = [0.01, -0.005, 0.007, -0.002, 0.003]

// Overnight fee percentage
overnight_fee = 0.0002

// Calculate equity curve
FOR i = 0 TO SIZEOF(daily_returns) - 1
    account_balance = account_balance + (account_balance * daily_returns[i])
    account_balance = account_balance - (account_balance * overnight_fee)
NEXT

RETURN account_balance

This code snippet is structured to simulate the impact of daily returns and overnight fees on an initial trading account balance. Here’s a step-by-step breakdown:

  • Initialization: The variable account_balance is set to 10000, representing the starting balance of the trading account.
  • Daily Returns Array: daily_returns is an array containing simulated daily return percentages, which affect the account balance positively or negatively.
  • Overnight Fee: The overnight_fee variable represents the fee charged for holding positions overnight, expressed as a percentage of the account balance.
  • Equity Curve Calculation: A FOR loop iterates through each element in the daily_returns array. For each day:
    • The account balance is updated based on the daily return.
    • The overnight fee is then deducted from the updated account balance.
  • Final Account Balance: After processing all daily returns and deducting overnight fees, the final account balance is returned.

This example helps illustrate how to manage and calculate changes in an equity curve with the inclusion of costs such as overnight fees, which are common in trading scenarios.

Related Post

Check out this related content for more information:

https://www.prorealcode.com/topic/more-accurate-equity-curve-with-overnight-fees-deducted/

Visit Link
What is a Snippet? A snippet is a small, reusable chunk of code designed to solve specific tasks quickly. Think of it as a shortcut that helps you achieve your coding goals without reinventing the wheel. How to Use: Simply copy the snippet and paste it into your project where needed. Don't forget to tweak it to fit your context. Snippets are not just time-savers; they're also learning tools to help you become a more efficient coder.
Vonasi Master
V-oyaging ON A S-mall I-ncome
Author’s Profile

Comments

Search Snippets

Showing some results...
Sorry, no result found!

Snippets Categories

global
35
indicator
133
strategy
171

Recent Snippets

How to Create a Simple MTF Trend Dashboard with EMA and SMA
indicator
This indicator builds a compact multi-timeframe (MTF) dashboard that shows whether price is trading above or below a [...]
How to Display Per-Bar Volume Accumulation in Real Time (Intrabar Updates)
global
This snippet tracks and displays the current bar’s accumulated volume while the bar is still forming, instead of only [...]
Ticks Counter: Count Tick Updates Per Bar on Tick or Time Charts
global
This snippet counts how many tick updates have occurred for the current bar by incrementing a per-bar counter on each [...]
How to Build a Step-Based Trailing Stop That Moves to Break-Even First
strategy
This snippet implements a step trailing stop that advances in fixed increments once price reaches predefined profit [...]
Utilizing Arrays to Track and Compare Indicator Values Within the Same Bar in ProBuilder
indicator
This ProBuilder code snippet demonstrates how to use arrays to compare the values of an indicator (RSI in this case) [...]
Logo Logo
Loading...