Spaces:
Sleeping
Sleeping
File size: 1,485 Bytes
7d3ed55 1e9f0e8 2f65dd5 17ad65a 0248df7 3d2e06f 0248df7 f892fb9 ed69b7c 0248df7 1e9f0e8 f892fb9 1e9f0e8 f892fb9 a757375 f892fb9 1e9f0e8 f892fb9 1e9f0e8 51029e5 1e9f0e8 166894c e233d14 166894c 09c1e81 86f0c30 1e9f0e8 82258fb cf30e6e 1e9f0e8 bad42ce 931f1ff 294a293 dac8f8f 1bfe6c3 bbf472e 3fecfd7 14c3507 86bce75 0c25214 62393ad 4cfb8a1 f7a3061 96741b4 f892fb9 4c9a5cc 41b1b37 dade767 166894c 609f278 aa683a2 b5668d7 2788bc8 037c98c 0248df7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | import gradio as gr
import altair as alt
import pandas as pd
import os
def create_portfolio_graph(amount):
# Calculate positions based on the provided amount
long_position = float(os.getenv('LONG_PORTION')) * amount
short_position = float(os.getenv('SHORT_PORTION')) * amount
# Data for the bars
positions = ['Long Position', 'Short Position']
percentages = [long_position, short_position]
data = pd.DataFrame({'Position': positions, 'Percentage': percentages})
# Creating the bar plot with adjusted width and colors
chart = alt.Chart(data).mark_bar().encode(
x=alt.X('Position:N', axis=alt.Axis(title=None)),
y=alt.Y('Percentage:Q', axis=alt.Axis(title='Funds')),
color=alt.Color('Position:N', scale=alt.Scale(range=['blue', 'red']))
).properties(width=400) # Adjust width as needed
return chart
with gr.Blocks() as demo:
title = gr.Markdown(
"""
# Insert Portfolio Value and Click Submit to See the Recommended Portfolio Allocation
"""
)
amount = gr.Number(value=0, label="Type in the total amount of funds in your portfolio including leverage")
button = gr.Button(value="Submit")
plot = gr.Plot(label="Portfolio Composition Chart")
demo.load(create_portfolio_graph, inputs=[amount], outputs=[plot])
button.click(create_portfolio_graph, [amount], plot)
if __name__ == "__main__":
demo.launch()
|