No topics yet. Start the conversation.

Summary

User supplied summary for the plot

Monthly performance breakdown by sector ytd

Description

The below description is supplied in free-text by the user

Novem Example Index top and bottom performers

This table is an example of how you can highlight top and bottom performers for a fictive equity index or portfolio. The code with comments is available below. Curious about the data side? Check out how we created the sample data. Want to learn more about novem and pandas? We have an article for that.

import pandas as pd
from novem import Plot
from novem.colors import StaticColor as SC, DynamicColor as DC
from novem.table import Selector as S

# grab our example numbers from novem data
df = pd.read_csv('nei_sector_perf.csv', index_col=0)

# let's convert our Contribution to bps, Basis points)

# Create a novem e-mail table `mtable`
tb = Plot('nei_sector_perf', type='table', config_path='test.conf') 

# add our data
df.pipe(tb)

# right align our nmbers
tb.cell.align = """
: : <
: 1: >
"""


# add some spacing to the left and right of numbers
tb.cell.padding = """
  : 1: x 2
-1   : t 1
  : 0  r 2
"""

# let's format our numbers, first set NAV and all following 
# numbers as decimal, then override Return as percent
tb.cell.format = """
 1: 1: ,.1%
"""


# use index colors
tb.colors.type = 'ix'

tb.colors = """
 1:-2   1:-2  bg red-300,neutral,green-300(_,0,_)^lin
-1      1:    bg red-300,neutral,green-300(_,0,_)^lin
 1:    -1     bg red-300,neutral,green-300(_,0,_)^lin
"""


# finaly let's bold the text and add a bottom border to the top row, we'll add 
# this manually as pandas slicing doens't make it easy to slice for the index 
# row
tb.cell.border = """
 0 : b 1 inverse
-1 : y 1 inverse
"""   # row 0, all columns, bottom 1 wide border
                                     # with the "inverse" color
tb.cell.text   = """
 0 : b
-1 : b
"""             # row 0, all columns, bold text

# add a caption to the table
tb.caption = """Sector performance by month of the individual sectors of the novem example index.

"""


# Let's add a discriptive name
tb.name = "Novem Example Index - Sector Performance by Month 2023"

# and a short summary
tb.summary = "Monthly performance breakdown by sector ytd"

# share it with the world
tb.shared += 'public'
tb.shared += 'chat'

# let's print our url
print(tb.url) # https://novem.no/p/NJy4w

tb.type = 'mtable'

with open(__file__,'r') as f:
  ctnt = f.read().replace('```','```') # turtles

  desc = f"""
# Novem Example Index top and bottom performers
This table is an example of how you can highlight top and bottom performers
for a fictive equity index or portfolio. The code with comments is available below.
Curious about the data side? [Check out how we created the sample data.](https://novem.no/blog/creating-the-novem-example-index/)
Want to learn more about novem and pandas? [We have an article for that.](https://novem.no/blog/novem-pandas/)

```
{ctnt}
```
"""

  tb.description = desc