-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from sharmasourab93/indices
NSE Indices
- Loading branch information
Showing
35 changed files
with
1,230 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
from datetime import datetime | ||
|
||
import pandas as pd | ||
import pytest | ||
|
||
from trade.nse.indices.nse_indices_config import INDICES, NSEIndexConfig | ||
from trade.nse.nse_config import DATE_FMT | ||
|
||
MARKET, COUNTRY = "NSE", "INDIA" | ||
DATED = datetime.today().strftime(DATE_FMT) | ||
|
||
|
||
@pytest.fixture | ||
def index_config(): | ||
return NSEIndexConfig(DATED, market=MARKET, country=COUNTRY) | ||
|
||
|
||
def test_get_fii_dii(index_config): | ||
fii_dii = index_config.get_fii_dii_report() | ||
assert isinstance(fii_dii, list) | ||
assert len(fii_dii) > 0 | ||
assert all(isinstance(item, dict) for item in fii_dii) | ||
|
||
|
||
def test_get_all_indices(index_config): | ||
indices = index_config.get_all_indices() | ||
assert isinstance(indices, dict) | ||
assert len(indices) > 0 | ||
assert all( | ||
isinstance(key, str) and isinstance(value, pd.DataFrame) | ||
for key, value in indices.items() | ||
) | ||
|
||
|
||
def test_get_quote_index(index_config): | ||
for index in INDICES: | ||
quote = index_config.get_quote_index(index) | ||
assert isinstance(quote, dict) | ||
cols = ("adv-dec", "symbol", "ohlc", "dated", "status") | ||
assert all(i in cols for i in quote.keys()) | ||
assert quote["symbol"] == index | ||
|
||
|
||
def test_get_quote_index_invalid_input(index_config): | ||
with pytest.raises(AttributeError): | ||
index_config.get_quote_index(None) | ||
|
||
|
||
def test_get_index_metrics(index_config): | ||
|
||
response = index_config.get_index_metrics() | ||
|
||
assert isinstance(response, dict) | ||
assert all(i in INDICES for i in response.keys()) | ||
|
||
|
||
def test_get_vix_history(index_config): | ||
start, end = "01-05-2024", "01-06-2024" | ||
response = index_config.get_vix_history(start, end) | ||
|
||
assert isinstance(response, dict) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 1 addition & 3 deletions
4
tests/test_nse/test_nse_all_stocks.py → ...st_nse/test_stocks/test_nse_all_stocks.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
tests/test_nse/test_nse_stock.py → tests/test_nse/test_stocks/test_nse_stock.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import pytest | ||
|
||
from trade.nse.indices.nse_indices_config import NSEIndexConfig | ||
from trade.option_chain.index_option_chain import IndexOptionChainAnalysis | ||
|
||
|
||
@pytest.fixture | ||
def index_option_chain_analysis(): | ||
return IndexOptionChainAnalysis( | ||
symbol="NIFTY", | ||
oc_data={ | ||
"records": { | ||
"data": [ | ||
{"strikePrice": 100, "CE_openInterest": 100, "PE_openInterest": 100} | ||
] | ||
}, | ||
"filtered": {"PE": {"totOI": 100}, "CE": {"totOI": 100}}, | ||
"timestamp": "2022-01-01 00:00:00", | ||
"expiryDates": ["2022-01-15", "2022-02-15"], | ||
"strikePrices": [100, 110, 120], | ||
"underlyingValue": 100, | ||
}, | ||
strike_multiples={"NIFTY": 10}, | ||
Config=NSEIndexConfig, | ||
) | ||
|
||
|
||
@pytest.mark.xfail(reason="Still not well integrated.") | ||
def test_index_option_chain_analysis(index_option_chain_analysis): | ||
result = index_option_chain_analysis.index_option_chain_analysis( | ||
symbol="NIFTY", expiry_day=15, delta=5, expiry_delta=1 | ||
) | ||
assert isinstance(result, dict) | ||
assert "symbol" in result | ||
assert "Expiry" in result | ||
assert "Max Put & Call OI" in result | ||
assert "Support at" in result | ||
assert "Resistance at" in result | ||
assert "Straddle" in result | ||
assert "Overall PCR" in result | ||
assert "Verdict" in result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# import pytest | ||
# | ||
# from trade.nse.nse_config import NSEConfig | ||
# from trade.option_chain.stock_option_chain import StockOptionChain | ||
# | ||
# | ||
# @pytest.fixture | ||
# def stock_option_chain(): | ||
# return StockOptionChain( | ||
# symbol="TATASTEEL", | ||
# oc_data={ | ||
# "records": { | ||
# "data": [ | ||
# {"strikePrice": 100, "CE_openInterest": 100, "PE_openInterest": 100} | ||
# ] | ||
# }, | ||
# "filtered": {"PE": {"totOI": 100}, "CE": {"totOI": 100}}, | ||
# "timestamp": "2022-01-01 00:00:00", | ||
# "expiryDates": ["2022-01-15", "2022-02-15"], | ||
# "strikePrices": [100, 110, 120], | ||
# "underlyingValue": 100, | ||
# }, | ||
# strike_multiples={"TATASTEEL": 10}, | ||
# Config=NSEConfig, | ||
# ) | ||
# | ||
# | ||
# pytest.mark.xfail(reason="Not Integrated yet.") | ||
# def test_get_select_stock_options_bhavcopy(stock_option_chain): | ||
# result = stock_option_chain.get_select_stock_options_bhavcopy( | ||
# symbol="TATASTEEL", expiry="2022-01-15" | ||
# ) | ||
# assert isinstance(result, tuple) | ||
# assert len(result) == 2 | ||
# assert isinstance(result[0], pd.DataFrame) | ||
# assert isinstance(result[1], pd.DataFrame) | ||
# assert result[0].shape[0] > 0 | ||
# assert result[1].shape[0] > 0 | ||
# | ||
# | ||
# pytest.mark.xfail(reason="Not Integrated.") | ||
# | ||
# | ||
# def test_stock_option_chain(stock_option_chain): | ||
# result = stock_option_chain.stock_option_chain( | ||
# symbol="TATASTEEL", delta=5, expiry_delta=1 | ||
# ) | ||
# assert isinstance(result, dict) | ||
# assert "OptionChain" in result | ||
# assert "Expiry" in result | ||
# assert "underlying_value" in result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import pytest | ||
|
||
from trade.ticker.yf import YFinance | ||
from trade.exchange.yf import YFinance | ||
|
||
|
||
@pytest.fixture | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from trade.exchange.market import Exchange, ExchangeArgs |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from typing import Literal, Optional, TypeVar | ||
|
||
from trade.option_chain.index_option_chain import IndexOptionChainAnalysis | ||
from trade.option_chain.stock_option_chain import StockOptionChain | ||
|
||
|
||
class NSEDataGeneric: | ||
|
||
def get_option_chain_analysis( | ||
self, oc_type: Literal["index", "equity"] | ||
) -> "OptionChainType": | ||
|
||
match oc_type: | ||
|
||
case "index": | ||
return self.option_chain_result(IndexOptionChainAnalysis) | ||
|
||
case "equity": | ||
return ( | ||
self.option_chain_result(StockOptionChain) if self.is_fno else None | ||
) | ||
|
||
case _: | ||
raise KeyError() | ||
|
||
def option_chain_result(self, OptionChain: type): | ||
|
||
option_chain_data = ( | ||
self._nse_config.get_option_chain_data.get_option_chain_data(self.symbol) | ||
) | ||
|
||
oc_obj = OptionChain(symbol, option_chain_data, self.dated, strike_multiples) | ||
|
||
return oc_obj.option_chain_output() | ||
|
||
def apply_indicators(self, Indicator: type) -> None: ... |
Empty file.
Oops, something went wrong.