candlestick-styling.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # Copyright 2021-2024 Avaiga Private Limited
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
  4. # the License. You may obtain a copy of the License at
  5. #
  6. # http://www.apache.org/licenses/LICENSE-2.0
  7. #
  8. # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
  9. # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
  10. # specific language governing permissions and limitations under the License.
  11. # -----------------------------------------------------------------------------------------
  12. # To execute this script, make sure that the taipy-gui package is installed in your
  13. # Python environment and run:
  14. # python <script>
  15. # You may need to install the yfinance package as well.
  16. # -----------------------------------------------------------------------------------------
  17. import yfinance
  18. from taipy.gui import Gui
  19. if __name__ == "__main__":
  20. # Extraction of a few days of stock historical data for AAPL using
  21. # the yfinance package (see https://pypi.org/project/yfinance/).
  22. # The returned value is a Pandas DataFrame.
  23. ticker = yfinance.Ticker("AAPL")
  24. stock = ticker.history(interval="1d", start="2018-08-18", end="2018-09-10")
  25. # Copy the DataFrame index to a new column
  26. stock["Date"] = stock.index
  27. options = {
  28. # Candlesticks that show decreasing values are orange
  29. "decreasing": {"line": {"color": "orange"}},
  30. # Candlesticks that show decreasing values are blue
  31. "increasing": {"line": {"color": "blue"}},
  32. }
  33. layout = {
  34. "xaxis": {
  35. # Hide the range slider
  36. "rangeslider": {"visible": False}
  37. }
  38. }
  39. page = """
  40. # Candlestick - Styling
  41. <|{stock}|chart|type=candlestick|x=Date|open=Open|close=Close|low=Low|high=High|options={options}|layout={layout}|>
  42. """
  43. Gui(page).run()