Serendipity2-0 / TradeManV1

0 stars 0 forks source link

Testing of Equity Module with Place Orders (#42) #49

Closed amolkittur closed 2 months ago

amolkittur commented 3 months ago

42

Description

This issue outlines the tasks involved in testing the equity module's order placement functionality. It includes steps from running the main equity module to updating the database at the end of the day.

Tasks

  1. Run the Equity Main Module

    • This module calculates and sorts instruments and writes them to a CSV file.
  2. Calculate Quantity in Equity File

    • 2.1 Calculate free cash based on Allocation percent.
    • 2.2 Retrieve the LTP (Last Traded Price) of the instrument.
    • 2.3 Calculate the quantity based on the above data.
    • 2.4 Once the quantity is calculated, update it back to Firebase in the strategy section.
  3. Place Orders

    • Execute the trading orders as per the calculated quantities.
  4. Update Trade State

    • After the orders are placed, ensure that the trade state is updated in the correct path in the strategies.
  5. Handling Exit Orders

    • If the orders include exit strategies, calculate the P&L and other relevant metrics.
    • Update these metrics in the correct database with accurate values.
  6. Handling Non-exit Orders

    • For orders that do not have exit strategies, update the holding collection in the database.
  7. End-of-Day Updates

    • At EOD, while sending out notifications, ensure that the accounts section is updated appropriately.
amolkittur commented 2 months ago

Orders Update

Status

Known Issue

Action Item

Next Steps

1Chinmay1 commented 2 months ago

I fixed the issue with yfinance but pushed the code before this issue was created it is pushed to feat- pystocks

Please check @amolkittur

amolkittur commented 2 months ago

@omkarh25 We are able to place the orders for the equity module. We need to make a few changes in the firebase so i am waiting for the admin page to be completed so that we can make the changes in the firebase without touching it

amolkittur commented 2 months ago

Bug Report: Inconsistent Quantity Handling in Firebase

Issue Description

There are two scenarios where the code fails to handle the qty field in Firebase correctly:

  1. First-time execution:

    • The qty field doesn't exist in Firebase initially.
    • The code updates qty while executing the strategy.
    • An error occurs because the code doesn't use the latest Firebase data.
  2. Subsequent executions:

    • The qty field exists in Firebase.
    • The code needs to update qty with available free cash.
    • Instead of using the latest qty, it uses the previous value.

Proposed Solution

Reload the Firebase database before placing orders to ensure the most up-to-date data is used.

Steps to Reproduce

  1. Run the code for the first time (observe error due to missing qty field).
  2. Run the code again (observe incorrect qty value being used).

Expected Behavior

The code should always use the most recent data from Firebase when calculating and updating the qty field.

Additional Notes

This issue affects the accuracy of order placement and may lead to unexpected behavior in the trading strategy.

amolkittur commented 2 months ago

@1Chinmay1
I have made some changes in the Stoploss function. Check the functions and also the values for all the three types of stoploss.

1Chinmay1 commented 2 months ago

@amolkittur ok will check and test it once

1Chinmay1 commented 2 months ago

@amolkittur
Tested the stoploss function tested with entry price as 100 Rs

short term SL multiplier is 9% Mid term SL multiplier is 18%

Case1: ltp is 95rs

for short_momentum: SL is 91 rs for mid_tfema: SL is 82 for mid_tfMomentum: 82

case 2: ltp is 120rs

for short_momentum: SL is 109.0 for mid_tfema: SL is 100.0 for mid_tfMomentum: 100.0

case 3:

ltp is 110rs

for short_momentum: SL is 100.0 for mid_tfema: SL is 91.0 for mid_tfMomentum: 82.0

1Chinmay1 commented 2 months ago

Edge Case: When calculating SL

Assuming the entry for a stock was on Day 1 at 100 rs and SL multiplier is set to 10% and the Stop loss type is full trailing SL so for Day 1 SL is 90

Day 2: stock gaped up by 10% hence the SL shifts to 100

Day 3 stock has gaped down by 11% Ideally in this case the SL should be hit and trade should be exited but what happens is SL changes to 90

amolkittur commented 2 months ago

The code is generating the reports with the new database and firebase format. Also the stoploss function has been tested

amolkittur commented 2 months ago

Closing this issue as all the tasks required to pass the Phase 1 are complete