Giter VIP home page Giter VIP logo

marketmomentum's Introduction

{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "{\n",
    " \"cells\": [\n",
    "  {\n",
    "   \"cell_type\": \"markdown\",\n",
    "   \"metadata\": {},\n",
    "   \"source\": [\n",
    "    \"# Description: \\n\",\n",
    "    \"MarketMomentum is a Streamlit application designed to generate custom reports for a selected stock and its benchmark. The user can choose the desired graphs and tables to be displayed in the report, which can be exported as an HTML or CSV file. The application also provides a snapshot of the stock's performance using the QuantStats library, which is saved as an HTML file and can be viewed within the application. \\n\",\n",
    "    \"\\n\",\n",
    "    \"The application uses the AgGrid component for table display and Streamlit's download_button function for report exportation. The snapshot HTML file is displayed using Streamlit's components.html function. \\n\",\n",
    "    \"\\n\",\n",
    "    \"The application's sidebar contains widgets for user input, including a text input for the stock symbol, a checkbox for including a benchmark, a text input for the benchmark symbol, date input widgets for the start and end dates, and buttons for Snapshot and Custom Report. \\n\",\n",
    "    \"\\n\",\n",
    "    \"Based on the user's input, the application displays the selected graphs and tables in the main section. It also provides download buttons for exporting the report to HTML and CSV files. The snapshot HTML file is displayed within the application.\"\n",
    "   ]\n",
    "  },\n",
    "  {\n",
    "   \"cell_type\": \"markdown\",\n",
    "   \"metadata\": {},\n",
    "   \"source\": [\n",
    "    \"The application would be beneficial for financial analysts, stock traders, portfolio managers, and individual investors who need to analyze and monitor the performance of specific stocks on a daily basis. It provides a comprehensive snapshot of a stock's performance and allows users to generate custom reports with selected graphs and tables, which can be exported for further analysis. The inclusion of a benchmark comparison also provides valuable context for the stock's performance.\"\n",
    "   ]\n",
    "  },\n",
    "  {\n",
    "   \"cell_type\": \"markdown\",\n",
    "   \"metadata\": {},\n",
    "   \"source\": [\n",
    "    \"## Features\\n\",\n",
    "    \"\\n\",\n",
    "    \"- **Home Page**: Enter a stock symbol to generate a custom report or see a key metrics snapshot.\\n\",\n",
    "    \"- **Snapshot**: Provides a comprehensive report of the selected stock's performance, including various metrics and visualizations.\\n\",\n",
    "    \"- **Benchmark Comparison**: Optional benchmark data can be included to compare to selected stock. Enter the stock market ticker symbol for the ETF or stock for results.\\n\",\n",
    "    \"- **Custom Report**: Allows users to select specific graphs and tables to display, creating a custom report tailored to their needs.\\n\",\n",
    "    \"- **Export**: Export the results of your custom report to HTML for graphs and tables, or as csv for table data. \\n\",\n",
    "    \"\\n\",\n",
    "    \"## Usage\\n\",\n",
    "    \"\\n\",\n",
    "    \"1. Start streamlit app from main_mvp.py\\n\",\n",
    "    \"2. Enter a stock symbol in the sidebar.\\n\",\n",
    "    \"3. Select a date range for analysis.\\n\",\n",
    "    \"4. Optionally, include a benchmark symbol for comparison. Supports NYSE ticker symbols.\\n\",\n",
    "    \"5. Click on 'Snapshot' to generate a comprehensive report, or 'Custom Report' to select specific metrics and visualizations for your report.\\n\",\n",
    "    \"6. Export your custom report to HTML or CSV \\n\",\n",
    "    \"\\n\",\n",
    "    \"## Environment\\n\",\n",
    "    \"\\n\",\n",
    "    \"conda create --name marketmomentum\\n\",\n",
    "    \"\\n\",\n",
    "    \"conda install streamlit streamlit-aggrid pandas numpy plotly streamlit-components quantstats\\n\",\n",
    "    \"\\n\",\n",
    "    \"\\n\",\n",
    "    \"### Installation\\n\",\n",
    "    \"\\n\",\n",
    "    \"Clone the repository and install the dependencies:\\n\",\n",
    "    \"\\n\",\n",
    "    \"```bash\\n\",\n",
    "    \"git clone https://github.com/jrebelo/MarketMomentum.git\\n\",\n",
    "    \"cd MarketMomentum\\n\",\n",
    "    \"```\\n\",\n",
    "    \"\\n\",\n",
    "    \"#### Additional Planned Features\\n\",\n",
    "    \"\\n\",\n",
    "    \"- Add definitions of each metric when hovering over the name\\n\",\n",
    "    \"- Add automatic stock analysis\\n\",\n",
    "    \"- LLM integration for analysis once the analysis algorithms are sufficient\"\n",
    "   ]\n",
    "  },\n",
    "  {\n",
    "   \"cell_type\": \"markdown\",\n",
    "   \"metadata\": {},\n",
    "   \"source\": [\n",
    "    \"TODO: here are the descriptions listed with numbers for easier reference that should be added as the user hovers over each object:\\n\",\n",
    "    \"\\n\",\n",
    "    \"1. `CAGR`: Compound Annual Growth Rate, the mean annual growth rate of an investment over a specified period of time longer than one year.\\n\",\n",
    "    \"2. `Sharpe`: The Sharpe ratio, a measure of risk-adjusted return.\\n\",\n",
    "    \"3. `Sortino`: The Sortino ratio, a variation of the Sharpe ratio that only factors in downside risk.\\n\",\n",
    "    \"4. `Max Drawdown`: The maximum observed loss from a peak to a trough of a portfolio, before a new peak is attained.\\n\",\n",
    "    \"5. `Volatility (ann.)`: The annualized standard deviation of returns, a measure of risk.\\n\",\n",
    "    \"6. `Calmar`: The Calmar ratio, a comparison of the average annual compounded rate of return and the maximum drawdown risk.\\n\",\n",
    "    \"7. `Expected Daily`: The expected daily return.\\n\",\n",
    "    \"8. `Expected Monthly`: The expected monthly return.\\n\",\n",
    "    \"9. `Expected Yearly`: The expected yearly return.\\n\",\n",
    "    \"10. `Cumulative Return`: The total return on an investment.\\n\",\n",
    "    \"11. `Prob. Sharpe Ratio`: The Probabilistic Sharpe Ratio, a measure of the probability that the expected Sharpe ratio of a strategy is greater than a benchmark Sharpe ratio.\\n\",\n",
    "    \"12. `Smart Sharpe`: A variation of the Sharpe ratio that attempts to adjust for skewness and kurtosis in the returns distribution.\\n\",\n",
    "    \"13. `Smart Sortino`: A variation of the Sortino ratio that attempts to adjust for skewness and kurtosis in the returns distribution.\\n\",\n",
    "    \"14. `Sortino/√2`: The Sortino ratio divided by the square root of 2, a normalization technique.\\n\",\n",
    "    \"15. `Smart Sortino/√2`: The Smart Sortino ratio divided by the square root of 2, a normalization technique.\\n\",\n",
    "    \"16. `Skew`: A measure of the asymmetry of the probability distribution of returns.\\n\",\n",
    "    \"17. `Kurtosis`: A measure of the \\\"tailedness\\\" of the probability distribution of returns.\\n\",\n",
    "    \"18. `Daily Value-at-Risk`: The estimated maximum amount that the investment is likely to lose in one day with a certain probability.\\n\",\n",
    "    \"19. `Gain/Pain Ratio`: The total of all monthly gains divided by the absolute total of all monthly losses.\\n\",\n",
    "    \"20. `Tail Ratio`: The ratio of the average return of the 10% of months with the highest returns to the average return of the 10% of months with the lowest returns.\\n\",\n",
    "    \"21. `Best Day`: The best single-day return.\\n\",\n",
    "    \"22. `Worst Day`: The worst single-day return.\\n\",\n",
    "    \"23. `Best Month`: The best single-month return.\\n\",\n",
    "    \"24. `Worst Month`: The worst single-month return.\\n\",\n",
    "    \"25. `Recovery Factor`: The ratio of total return to maximum drawdown.\\n\",\n",
    "    \"26. `Ulcer Index`: A measure of the depth and duration of drawdowns in prices.\\n\",\n",
    "    \"27. `Worst Year`: The worst single-year return.\\n\",\n",
    "    \"28. `Best Year`: The best single-year return.\\n\",\n",
    "    \"29. `Payoff Ratio`: The ratio of the average winning trade to the average losing trade.\\n\",\n",
    "    \"30. `Profit Factor`: The ratio of gross profit to gross loss.\\n\",\n",
    "    \"31. `CPC Index`: A measure of the robustness of a strategy, defined as the product of the Probabilistic Sharpe Ratio and the Profit Factor.\\n\",\n",
    "    \"32. `Risk of Ruin`: The probability of an investment depleting to a specified level.\\n\",\n",
    "    \"33. `Common Sense Ratio`: A ratio used to analyze the performance of an investment by comparing the expected return and the maximum drawdown.\"\n",
    "   ]\n",
    "  },\n",
    "  {\n",
    "   \"cell_type\": \"markdown\",\n",
    "   \"metadata\": {},\n",
    "   \"source\": [\n",
    "    \"TODO: here are the descriptions listed with numbers for easier reference that should be added as the user hovers over each object:\\n\",\n",
    "    \"\\n\",\n",
    "    \"1. `Cumulative Return`: The total return on an investment.\\n\",\n",
    "    \"2. `CAGR`: Compound Annual Growth Rate, the mean annual growth rate of an investment over a specified period of time longer than one year.\\n\",\n",
    "    \"3. `Sharpe`: The Sharpe ratio, a measure of risk-adjusted return.\\n\",\n",
    "    \"4. `Prob. Sharpe Ratio`: The Probabilistic Sharpe Ratio, a measure of the probability that the expected Sharpe ratio of a strategy is greater than a benchmark Sharpe ratio.\\n\",\n",
    "    \"5. `Smart Sharpe`: A variation of the Sharpe ratio that attempts to adjust for skewness and kurtosis in the returns distribution.\\n\",\n",
    "    \"6. `Sortino`: The Sortino ratio, a variation of the Sharpe ratio that only factors in downside risk.\\n\",\n",
    "    \"7. `Smart Sortino`: A variation of the Sortino ratio that attempts to adjust for skewness and kurtosis in the returns distribution.\\n\",\n",
    "    \"8. `Sortino/√2`: The Sortino ratio divided by the square root of 2, a normalization technique.\\n\",\n",
    "    \"9. `Smart Sortino/√2`: The Smart Sortino ratio divided by the square root of 2, a normalization technique.\\n\",\n",
    "    \"10. `Max Drawdown`: The maximum observed loss from a peak to a trough of a portfolio, before a new peak is attained.\\n\",\n",
    "    \"11. `Volatility (ann.)`: The annualized standard deviation of returns, a measure of risk.\\n\",\n",
    "    \"12. `Calmar`: The Calmar ratio, a comparison of the average annual compounded rate of return and the maximum drawdown risk.\\n\",\n",
    "    \"13. `Skew`: A measure of the asymmetry of the probability distribution of returns.\\n\",\n",
    "    \"14. `Kurtosis`: A measure of the \\\"tailedness\\\" of the probability distribution of returns.\\n\",\n",
    "    \"15. `Expected Daily`: The expected daily return.\\n\",\n",
    "    \"16. `Expected Monthly`: The expected monthly return.\\n\",\n",
    "    \"17. `Expected Yearly`: The expected yearly return.\\n\",\n",
    "    \"18. `Best Day`: The best single-day return.\\n\",\n",
    "    \"19. `Worst Day`: The worst single-day return.\\n\",\n",
    "    \"20. `Best Month`: The best single-month return.\\n\",\n",
    "    \"21. `Worst Month`: The worst single-month return.\\n\",\n",
    "    \"22. `Recovery Factor`: The ratio of total return to maximum drawdown.\\n\",\n",
    "    \"23. `Ulcer Index`: A measure of the depth and duration of drawdowns in prices.\\n\",\n",
    "    \"24. `Worst Year`: The worst single-year return.\\n\",\n",
    "    \"25. `Best Year`: The best single-year return.\\n\",\n",
    "    \"26. `Payoff Ratio`: The ratio of the average winning trade to the average losing trade.\\n\",\n",
    "    \"27. `Profit Factor`: The ratio of gross profit to gross loss.\\n\",\n",
    "    \"28. `Common Sense Ratio`: A ratio used to analyze the performance of an investment by comparing the expected return and the maximum drawdown.\\n\",\n",
    "    \"29. `CPC Index`: A measure of the robustness of a strategy, defined as the product of the Probabilistic Sharpe Ratio and the Profit Factor.\\n\",\n",
    "    \"30. `Risk of Ruin`: The probability of an investment depleting to a specified level.\\n\",\n",
    "    \"31. `Daily Value-at-Risk`: The estimated maximum amount that the investment is likely to lose in one day with a certain probability.\\n\",\n",
    "    \"32. `Gain/Pain Ratio`: The total of all monthly gains divided by the absolute total of all monthly losses.\\n\",\n",
    "    \"33. `Tail Ratio`: The ratio of the average return of the 10% of months with the highest returns to the average return of the 10% of months with the lowest returns.\"\n",
    "   ]\n",
    "  },\n",
    "  {\n",
    "   \"cell_type\": \"markdown\",\n",
    "   \"metadata\": {},\n",
    "   \"source\": [\n",
    "    \"Here are a few suggestions to make the app more user-friendly:\\n\",\n",
    "    \"\\n\",\n",
    "    \"1. **Input Validation**: Add validation for user inputs. For example, check if the entered stock symbol or benchmark symbol is valid. If not, display an error message to the user.\\n\",\n",
    "    \"\\n\",\n",
    "    \"2. **Loading Indicators**: When fetching data or generating reports, which might take some time, show a loading indicator to inform the user that the process is ongoing.\\n\",\n",
    "    \"\\n\",\n",
    "    \"3. **Help Texts and Tooltips**: Provide help texts or tooltips for inputs and controls to guide the user on what to enter or what each control does.\\n\",\n",
    "    \"\\n\",\n",
    "    \"4. **Error Handling**: Implement proper error handling. If something goes wrong (like a failed data fetch), show a user-friendly error message.\\n\",\n",
    "    \"\\n\",\n",
    "    \"5. **Responsive Design**: Ensure the app is responsive and looks good on various screen sizes.\\n\",\n",
    "    \"\\n\",\n",
    "    \"6. **Default Values**: Where applicable, provide sensible default values. For example, the start date could default to one year ago instead of 1985.\\n\",\n",
    "    \"\\n\",\n",
    "    \"7. **Organize Inputs**: Group related inputs together in the sidebar to make the interface cleaner and more intuitive.\\n\",\n",
    "    \"\\n\",\n",
    "    \"8. **Searchable Dropdowns**: If the list of options in the dropdown menus gets too long, consider making them searchable to improve user experience.\\n\",\n",
    "    \"\\n\",\n",
    "    \"9. **Pagination for Tables**: If tables can get very long, consider adding pagination to improve load times and usability.\\n\",\n",
    "    \"\\n\",\n",
    "    \"10. **Interactive Charts**: Consider using interactive charts that allow users to zoom, pan, and hover over data points to see their values.\\n\",\n",
    "    \"\\n\",\n",
    "    \"Remember, user-friendliness often comes from iterative feedback and improvements. Consider getting user feedback regularly and making necessary adjustments based on that feedback.\"\n",
    "   ]\n",
    "  },\n",
    "  {\n",
    "   \"cell_type\": \"markdown\",\n",
    "   \"metadata\": {},\n",
    "   \"source\": [\n",
    "    \"The application can handle the following errors:\\n\",\n",
    "    \"\\n\",\n",
    "    \"1. **Invalid Stock Symbol**: If the user enters an invalid stock symbol, the application should catch the error and display a user-friendly message. This can be done by checking the response from the `qs.utils.download_returns(symbol)` function.\\n\",\n",
    "    \"\\n\",\n",
    "    \"2. **Invalid Benchmark Symbol**: Similar to the stock symbol, the application should handle cases where the user enters an invalid benchmark symbol.\\n\",\n",
    "    \"\\n\",\n",
    "    \"3. **Invalid Date Range**: The application should handle cases where the user enters an invalid date range. For example, the start date should not be later than the end date.\\n\",\n",
    "    \"\\n\",\n",
    "    \"4. **Data Unavailability**: The application should handle cases where data for the specified stock symbol or benchmark symbol is not available for the specified date range.\"\n",
    "   ]\n",
    "  },\n",
    "  {\n",
    "   \"cell_type\": \"markdown\",\n",
    "   \"metadata\": {},\n",
    "   \"source\": [\n",
    "    \"V1 is completed. V2 TODO:\\n\",\n",
    "    \"The code you provided is using the `quantstats` package to analyze stock data and generate various graphs and tables. However, it does not automatically generate a 10-sentence analysis of the data. \\n\",\n",
    "    \"\\n\",\n",
    "    \"To generate a 10-sentence analysis, you would need to use Natural Language Processing (NLP) techniques. One possible approach could be to use a package like `nltk` or `spaCy` to analyze the data and generate sentences based on the analysis. \\n\",\n",
    "    \"\\n\",\n",
    "    \"However, this would require a significant amount of additional code and a good understanding of NLP techniques. It's also worth noting that the quality of the analysis would depend on the complexity of the NLP model used. \\n\",\n",
    "    \"\\n\",\n",
    "    \"Here's a very basic example of how you might use `nltk` to generate a sentence based on the mean return of the stock:\\n\",\n",
    "    \"\\n\"\n",
    "   ]\n",
    "  },\n",
    "  {\n",
    "   \"cell_type\": \"code\",\n",
    "   \"execution_count\": null,\n",
    "   \"metadata\": {},\n",
    "   \"outputs\": [],\n",
    "   \"source\": [\n",
    "    \"import nltk\\n\",\n",
    "    \"\\n\",\n",
    "    \"mean_return = stock.mean()\\n\",\n",
    "    \"\\n\",\n",
    "    \"if mean_return > 0:\\n\",\n",
    "    \"    sentence = \\\"The average return of the stock is positive.\\\"\\n\",\n",
    "    \"else:\\n\",\n",
    "    \"    sentence = \\\"The average return of the stock is negative.\\\"\\n\",\n",
    "    \"\\n\",\n",
    "    \"nltk.word_tokenize(sentence)\"\n",
    "   ]\n",
    "  },\n",
    "  {\n",
    "   \"cell_type\": \"markdown\",\n",
    "   \"metadata\": {},\n",
    "   \"source\": [\n",
    "    \"\\n\",\n",
    "    \"\\n\",\n",
    "    \"This is a very simple example and real-world usage would likely involve much more complex analysis and sentence generation.\"\n",
    "   ]\n",
    "  },\n",
    "  {\n",
    "   \"cell_type\": \"markdown\",\n",
    "   \"metadata\": {},\n",
    "   \"source\": [\n",
    "    \"V1 is completed. V2 TODO: This code block is designed to fetch daily returns for a specified stock and, if provided, a benchmark symbol. It uses the `streamlit` library to manage session state and display errors.\\n\",\n",
    "    \"\\n\",\n",
    "    \"1. It first checks if the 'stock' or 'symbol' keys are not in the session state, or if the 'symbol' in the session state does not match the provided symbol. If any of these conditions are met, it downloads the returns for the provided symbol and updates the session state.\\n\",\n",
    "    \"\\n\",\n",
    "    \"2. It then pauses for half a second to prevent overloading the server with requests.\\n\",\n",
    "    \"\\n\",\n",
    "    \"3. If a benchmark symbol is provided, it downloads the returns for the benchmark and filters them for the selected date range. If the resulting DataFrame is empty (indicating that no data could be found for the benchmark symbol in the given date range), it displays an error message and stops execution.\\n\",\n",
    "    \"\\n\",\n",
    "    \"4. It retrieves the 'stock' from the session state, filters the returns for the selected date range, and reconstructs the price data from the returns. If the resulting DataFrame is empty (indicating that no data could be found for the symbol in the given date range), it displays an error message and stops execution.\\n\",\n",
    "    \"\\n\",\n",
    "    \"5. If an `IndexError` occurs at any point during this process, it displays an error message indicating that an `IndexError` occurred, along with the details of the error, and stops execution.\\n\",\n",
    "    \"\\n\",\n",
    "    \"6. If any other type of exception occurs, it displays an error message indicating that an error occurred, along with the details of the error, and stops execution.\"\n",
    "   ]\n",
    "  }\n",
    " ],\n",
    " \"metadata\": {\n",
    "  \"kernelspec\": {\n",
    "   \"display_name\": \"quantstats\",\n",
    "   \"language\": \"python\",\n",
    "   \"name\": \"python3\"\n",
    "  },\n",
    "  \"language_info\": {\n",
    "   \"name\": \"python\",\n",
    "   \"version\": \"3.12.3\"\n",
    "  }\n",
    " },\n",
    " \"nbformat\": 4,\n",
    " \"nbformat_minor\": 2\n",
    "}\n"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}

marketmomentum's People

Contributors

ranaroussi avatar jonrebelo avatar galarosa avatar nadyka avatar s0ap avatar binary-signal avatar taohu88 avatar amirnajafi avatar bartstolarek avatar djl0 avatar drusakov778 avatar yarimiz avatar dependabot[bot] avatar manhinhang avatar ctjlewis avatar duxiaoyao avatar gabrieljenik avatar grizzlybearg avatar lau-jay avatar jgopel avatar kartiksubbarao avatar tradingdominion avatar snowhit3 avatar whisperes avatar dependabot-preview[bot] avatar git-shogg avatar gmjohns avatar jatorna avatar rmfish avatar

Stargazers

 avatar

Forkers

jonrebelo

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.