Profit / loss trading calculator for share market historical data

Click For Summary
SUMMARY

The discussion focuses on developing a share market trading calculator that computes profit and loss using historical data and moving averages. The user has implemented basic buy and sell formulas but struggles with managing multiple transactions and tracking equity. Key equations include calculating profit as the difference between buy and sell prices multiplied by volume. The user emphasizes the need for a data structure, such as a dataframe, to store stock names, values, and quantities owned.

PREREQUISITES
  • Understanding of financial trading concepts, specifically profit and loss calculations
  • Familiarity with Python programming and data manipulation using libraries like Pandas
  • Knowledge of moving averages and their application in stock trading
  • Experience with historical data retrieval for stock prices
NEXT STEPS
  • Implement a Pandas dataframe to manage stock names, values, and quantities owned
  • Research methods to retrieve historical stock prices using APIs or web scraping
  • Learn about advanced trading strategies involving multiple buy and sell transactions
  • Explore the use of moving averages in trading algorithms for better decision-making
USEFUL FOR

Developers creating trading applications, financial analysts, and anyone interested in automating profit/loss calculations for stock trading.

mp3streetpart
Messages
3
Reaction score
0

Homework Statement



Share market trading calculator.
I have tried to write code to calculate the buy and sell with profit/loss on historical data using moving averages. I'm am not interested in leverage yet.

bank = 10000
equity = 10000
sell = is current price of an instrument on the stock market either in the buy or sell routine.

Homework Equations


The difference in Buy price to sell price times volume.

The Attempt at a Solution


Buy formula
bank = bank - (10000 * sell) Remove money from bank to buy
profit = profit - (10000 * sell) Value to take to sell formula for profit/loss

Sell formula
profit = equity + ((10000 * sell ) + profit) Find profit/loss and compare against Buy
bank = profit: profit = 0


It works for a single buy and sell but I can't work out how to add more buys and sells to the bank or what to do with equity.
 
Physics news on Phys.org
It's a little vague, but it looks like Equity should equal the current value of the stock that you own, at a particular time. You'd need to have a dataframe or some way of holding the stock names and values and how many shares you own of each. Then I guess you have a way to pull the share price for any given historical date?

When you sell shares, then equity is reduced, and bank increases.

At any particular time the value of (Bank + Equity) before a transaction should equal to (Bank + Equity) after transaction.
 

Similar threads

  • · Replies 46 ·
2
Replies
46
Views
5K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 133 ·
5
Replies
133
Views
27K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 3 ·
Replies
3
Views
3K
Replies
1
Views
2K
  • · Replies 30 ·
2
Replies
30
Views
5K