> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mavera.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Sector Performance → Vertical Prioritization

### Scenario

Your sales team targets multiple verticals but can't pursue all equally. Alpha Vantage's `SECTOR` function returns real-time and historical performance by sector. This job maps sector momentum to marketing effort — invest messaging resources in growing sectors, adopt defensive positioning in declining ones, and generate vertical-specific campaign copy for the top priorities.

**Flow:** Alpha Vantage `GET ?function=SECTOR` → Rank by performance → Mavera `POST /mave/chat` + `POST /generations` → Vertical priority matrix + copy

### Code

<CodeGroup>
  ```python Python theme={"dark"}
  import os, requests, time

  AV_KEY = os.environ["ALPHA_VANTAGE_KEY"]
  AV_BASE = "https://www.alphavantage.co/query"
  MV = os.environ["MAVERA_API_KEY"]
  MV_BASE = "https://app.mavera.io/api/v1"
  MV_H = {"Authorization": f"Bearer {MV}", "Content-Type": "application/json"}

  PRODUCT = "marketing analytics platform"

  # 1. Fetch sector performance
  r = requests.get(AV_BASE, params={"function": "SECTOR", "apikey": AV_KEY})
  r.raise_for_status()
  sector_data = r.json()

  timeframes = {
      "1 Day": "Rank A: Real-Time Performance",
      "1 Month": "Rank D: Month Performance",
      "3 Months": "Rank E: Quarter Performance",
      "1 Year": "Rank G: Year Performance",
  }

  sector_summary = []
  for label, key in timeframes.items():
      data = sector_data.get(key, {})
      sorted_sectors = sorted(data.items(), key=lambda x: float(x[1].replace("%","")), reverse=True)
      sector_summary.append(f"\n**{label}:**")
      for sector, perf in sorted_sectors:
          sector_summary.append(f"  {sector}: {perf}")

  performance_text = "\n".join(sector_summary)
  print(f"Sector data retrieved across {len(timeframes)} timeframes")

  # 2. Mave prioritization
  priority = requests.post(f"{MV_BASE}/mave/chat", headers=MV_H, json={
      "message": f"Marketing strategist. We sell a {PRODUCT}.\n\n"
          f"SECTOR PERFORMANCE:\n{performance_text}\n\n"
          "Create a VERTICAL PRIORITIZATION MATRIX:\n\n"
          "For each sector:\n"
          "1. **Momentum Score** (1-10) — based on recent vs long-term performance\n"
          "2. **Marketing Investment** — Increase / Maintain / Decrease\n"
          "3. **Messaging Strategy** — Growth narrative vs efficiency narrative vs stability narrative\n"
          "4. **Key Angle** — One sentence positioning for this vertical\n"
          "5. **Budget Recommendation** — % of total marketing budget\n\n"
          "Rank by priority. Top 3 get detailed campaign angles."
  }).json()
  print(f"\n{priority.get('content', '')[:2000]}")

  # 3. Generate copy for top sector
  gen = requests.post(f"{MV_BASE}/generations", headers=MV_H, json={
      "prompt": f"Based on this vertical prioritization:\n\n{priority.get('content','')[:2000]}\n\n"
          f"Generate campaign copy for the TOP-RANKED sector targeting our {PRODUCT}.\n\n"
          "Include:\n"
          "1. Landing page headline + subheadline\n"
          "2. Three value propositions (sector-specific)\n"
          "3. Email subject line + preview text for outbound\n"
          "4. LinkedIn ad (headline + body + CTA)\n"
          "5. Case study headline template\n\n"
          "Reference sector momentum. Make the copy feel industry-native.",
  }).json()
  print(f"\n{'='*60}\nTOP SECTOR CAMPAIGN COPY\n{'='*60}")
  print(gen.get("output", gen.get("content", ""))[:1500])
  ```

  ```javascript JavaScript theme={"dark"}
  const AV_KEY = process.env.ALPHA_VANTAGE_KEY;
  const AV_BASE = "https://www.alphavantage.co/query";
  const MV = process.env.MAVERA_API_KEY;
  const MV_BASE = "https://app.mavera.io/api/v1";
  const MV_H = { Authorization: `Bearer ${MV}`, "Content-Type": "application/json" };

  const PRODUCT = "marketing analytics platform";

  // 1. Sector performance
  const sectorData = await (await fetch(`${AV_BASE}?function=SECTOR&apikey=${AV_KEY}`)).json();

  const timeframes = {
    "1 Day": "Rank A: Real-Time Performance",
    "1 Month": "Rank D: Month Performance",
    "3 Months": "Rank E: Quarter Performance",
    "1 Year": "Rank G: Year Performance",
  };

  let performanceText = "";
  for (const [label, key] of Object.entries(timeframes)) {
    const data = sectorData[key] || {};
    const sorted = Object.entries(data).sort((a, b) =>
      parseFloat(b[1]) - parseFloat(a[1]));
    performanceText += `\n**${label}:**\n${sorted.map(([s, p]) => `  ${s}: ${p}`).join("\n")}`;
  }
  console.log(`Sector data across ${Object.keys(timeframes).length} timeframes`);

  // 2. Prioritization
  const priority = await fetch(`${MV_BASE}/mave/chat`, { method: "POST", headers: MV_H,
    body: JSON.stringify({ message: `We sell a ${PRODUCT}.\n\nSECTOR PERFORMANCE:\n${performanceText}\n\nVertical prioritization matrix: Momentum (1-10), Investment (increase/maintain/decrease), Messaging strategy, Key angle, Budget %. Top 3 get campaign angles.` }),
  }).then(r => r.json());
  console.log((priority.content || "").slice(0, 2000));

  // 3. Top sector copy
  const gen = await fetch(`${MV_BASE}/generations`, { method: "POST", headers: MV_H,
    body: JSON.stringify({ prompt: `From prioritization:\n\n${(priority.content||"").slice(0,2000)}\n\nCampaign for TOP sector targeting ${PRODUCT}.\n\n1. Landing page headline+sub\n2. Three value props\n3. Email subject+preview\n4. LinkedIn ad\n5. Case study headline\n\nReference momentum. Industry-native copy.` }),
  }).then(r => r.json());
  console.log(`\n${"=".repeat(60)}\nTOP SECTOR CAMPAIGN COPY`);
  console.log((gen.output || gen.content || "").slice(0, 1500));
  ```
</CodeGroup>

### Example Output

```text theme={"dark"}
Sector data across 4 timeframes

VERTICAL PRIORITIZATION MATRIX:
| Sector | Momentum | Investment | Strategy | Budget |
|--------|----------|------------|----------|--------|
| Technology | 9/10 | Increase | Growth narrative | 30% |
| Healthcare | 7/10 | Increase | Efficiency | 20% |
| Energy | 6/10 | Maintain | Stability | 15% |
| Financials | 5/10 | Maintain | Efficiency | 15% |
| Real Estate | 3/10 | Decrease | Survival | 5% |

TOP SECTOR CAMPAIGN COPY (Technology)
============================================================
1. HEADLINE: Marketing Analytics Built for Tech's Growth Pace
   SUB: When your sector grows 18% YoY, your analytics can't lag.

2. VALUE PROPS:
   • Ship campaigns at sprint speed — not quarterly planning cycles
   • Attribution for PLG funnels — track product-led → sales-assisted
   • Benchmark against 200+ SaaS companies in our index

3. EMAIL: "Your sector grew 18% — did your pipeline keep up?"
   Preview: Tech marketing leaders are outpacing revenue growth. Here's how.

4. LINKEDIN: "Tech is outperforming every sector by 2x this quarter.
   Is your marketing analytics keeping pace?" → See the benchmark →
```

### Error Handling

<AccordionGroup>
  <Accordion title="Sector naming">Alpha Vantage uses SEC sector names (e.g., "Information Technology" not "Tech"). Map to your internal vertical names before generating copy.</Accordion>
  <Accordion title="Single API call">The `SECTOR` function returns all timeframes in one call — only 1 of your 25 daily free calls. Cache the response for the full day.</Accordion>
  <Accordion title="Negative performance">Sectors with negative returns need defensive messaging, not growth messaging. The Mave prompt handles this via the "stability narrative" strategy option.</Accordion>
</AccordionGroup>
