{ "cells": [ { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "import math\n", "import pandas as pd\n", "\n", "def vix_calculator(vix, spy, days=365):\n", " score = ( (vix / math.sqrt(days)) / 100 )\n", " return spy*(1-score), spy*(1+score)\n", "\n", "# val1, val2 = (vix_spy_csv('VIX.csv'))\n", "# print ('Volatility Range: ' + str(val1) + ' - ' + str(val2))" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
01
0SPY407.20
1VIX20.02
\n", "
" ], "text/plain": [ " 0 1\n", "0 SPY 407.20\n", "1 VIX 20.02" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pd.read_csv('VIX.csv', header=None)" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
01
0SPY399.07
1VIX22.70
\n", "
" ], "text/plain": [ " 0 1\n", "0 SPY 399.07\n", "1 VIX 22.70" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = pd.read_excel('VIX.xlsx', header=None)\n", "df" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "IMPORTANT: You are using gradio version 3.13.0, however version 3.14.0 is available, please upgrade.\n", "--------\n", "Running on local URL: http://127.0.0.1:7873\n", "\n", "To create a public link, set `share=True` in `launch()`.\n" ] }, { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" }, { "name": "stdout", "output_type": "stream", "text": [ "{'SPY': 399.07, 'VIX': 22.7}\n", "(394.3283607853106, 403.81163921468936)\n" ] } ], "source": [ "import gradio as gr\n", "import pandas as pd\n", "import numpy as np\n", "import os\n", "\n", "# os.system('pip install openpyxl')\n", "\n", "#multiple inputs are passed as arguments for the same function greet\n", "def greet(file1):\n", " # df = pd.read_csv(file1.name)\n", " if 'csv' in file1.name:\n", " df = pd.read_csv(file1.name, header=None)\n", " df[0] = df[0].apply(lambda x : x.replace(',', ''))\n", "\n", " if 'xlsx' in file1.name:\n", " df = pd.read_excel(file1.name, header=None)\n", " df[0] = df[0].apply(lambda x : x.replace(',', ''))\n", "\n", " df.index = df.pop(0)\n", " vix_spy_dict = df.to_dict()[1]\n", "\n", " print(vix_spy_dict)\n", "\n", " output = vix_calculator(vix_spy_dict['VIX'], vix_spy_dict['SPY'], days=365)\n", "\n", " print(output)\n", " return str(output)\n", "\n", "# iface = gr.Interface(fn=greet, inputs=[\"file\", \"file\", gr.inputs.Textbox(placeholder=\"Enter Question here...\")], outputs=\"text\")\n", "iface = gr.Interface(fn=greet, inputs=['file'], outputs=\"text\")\n", "# iface.launch(share=True)\n", "iface.launch(share=False)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.13" }, "orig_nbformat": 4, "vscode": { "interpreter": { "hash": "fdf377d643bc1cb065454f0ad2ceac75d834452ecf289e7ba92c6b3f59a7cee1" } } }, "nbformat": 4, "nbformat_minor": 2 }