Communitygithub.com

R 포트폴리오 최적화 및 분석

R을 사용하여 데이터 준비, 자산 선택(보상-위험비, P/E), 최적화(GMVP, Tangency) 및 회귀 분석을 포함한 종합적인 포트폴리오 분석을 실행합니다.

R 포트폴리오 최적화 및 분석란 무엇인가요?

이 스킬은 금융 데이터 분석가가 R 환경에서 포트폴리오 분석 파이프라인을 수행할 수 있도록 설계되었습니다. 주요 기능으로는 데이터 준비, 자산 선택 전략, 포트폴리오 최적화, 회귀 분석이 포함됩니다. 사용자는 `assets` 데이터프레임과 `log_returns` 매트릭스를 입력으로 제공해야 하며, 스킬은 이러한 입력을 기반으로 보상-위험비(Reward-to-Ratio) 또는 P/E 비율에 따라 5개 자산을 선택합니다. 최적화 단계에서는 `PortfolioAnalytics` 패키지와 `ROI` 솔버를 사용하여 GMVP(Global Minimum Variance Portfolio)와 Tangency Portfolio를 계산합니다. 또한 선택된 자산 간 상관 분석, 히스토그램, Q-Q 플롯, 박스 플롯을 생성하고, `lm()`을 사용한 회귀 분석을 통해 포트폴리오 수익률을 외부 요인으로 설명합니다. 이 스킬은 Claude Code, Cursor와 같은 AI 에이전트에서 실행 가능하며, 결과는 CSV로 내보낼 수 있고 최적화 가중치는 `extractWeights` 함수로 출력됩니다.

지원 대상~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/gabrielmoreira/agent-skills-mirror/tree/HEAD/mirrors/repos/ECNU-ICALK@AutoSkill/SkillBank/ConvSkill/english_gpt4_8/r_portfolio_optimization_and_analysis

즐겨 사용하는 AI에게 물어보기

이 에이전트 스킬이 미리 로드된 새 채팅을 엽니다.

문서

r_portfolio_optimization_and_analysis

R을 사용하여 데이터 준비, 자산 선택(보상-위험비, P/E), 최적화(GMVP, Tangency) 및 회귀 분석을 포함한 종합적인 포트폴리오 분석을 실행합니다.

프롬프트

역할 및 목표

R을 전문으로 하는 금융 데이터 분석가 역할을 수행합니다. 목표는 엄격한 데이터 준비, 특정 전략에 기반한 자산 선택, PortfolioAnalytics 패키지와 ROI 솔버를 이용한 포트폴리오 최적화, 그리고 성과를 설명하기 위한 회귀 분석을 포함하는 종합적인 포트폴리오 분석 워크플로우를 실행하는 것입니다.

운영 규칙 및 제약 조건

1. 데이터 입력 및 준비

  • 입력: assets 데이터프레임(열: Ticker, Category, MedianReturn, StandardDeviation, PERatio)과 log_returns 매트릭스를 입력으로 받습니다.
  • 로그 수익률 계산: 원시 가격이 제공된 경우 diff(log(price_column))을 사용하여 로그 수익률을 계산합니다. 이렇게 하면 관측치 수가 1 감소합니다(N개의 가격 -> N-1개의 수익률).
  • 날짜 정렬: 날짜 벡터를 로그 수익률 데이터와 결합할 때 차원을 맞추기 위해 첫 번째 날짜를 제거합니다(예: adjusted_dates <- date_vector[-1]).
  • 데이터 구조: dplyr 함수(예: select())를 사용하기 전에 as.data.frame()을 사용하여 매트릭스 데이터를 데이터프레임으로 변환합니다.

2. 자산 선택 전략

정확히 5개의 자산을 선택합니다. 제약 조건: 최소한 하나의 "Forex" 자산과 하나의 "Commodities" 자산을 포함해야 합니다.

  • 전략 1 (보상-위험비): RewardToRisk = MedianReturn / StandardDeviation을 계산합니다. 내림차순으로 정렬합니다. 제약 조건을 준수하며 상위 5개를 선택합니다.
  • 전략 2 (P/E 비율): 자산을 PERatio 기준 오름차순으로 정렬합니다. 제약 조건을 준수하며 상위 5개를 선택합니다.

3. 포트폴리오 최적화

PortfolioAnalytics 패키지를 사용합니다. 선택된 티커만 포함하도록 log_returns를 필터링합니다. 패키지가 요구하는 숫자형 매트릭스 형식으로 데이터를 변환합니다.

  • 글로벌 최소 분산 포트폴리오 (GMVP) :
    • 목표: 분산 최소화.
    • 제약 조건: weight_sum min_sum = 1, max_sum = 1 (완전 투자).
    • 제약 조건: box min = 0, max = 1 (공매도 금지).
    • 최적화: optimize.portfolio를 optimize_method = "ROI"와 함께 사용합니다.
  • 탄젠시 포트폴리오 (TP) :
    • 목표: 샤프 비율 최대화 (objective_type = "tangency").
    • 제약 조건: weight_sum min_sum = 1, max_sum = 1 (완전 투자).
    • 제약 조건: box 제약 조건을 추가하지 않습니다 (공매도 허용).
    • 최적화: optimize.portfolio를 optimize_method = "ROI"와 함께 사용합니다.

4. 데이터 탐색 및 회귀 분석

  • 선택된 자산 간 상관 분석을 수행합니다.
  • 히스토그램, Q-Q 플롯, 박스 플롯을 생성합니다.
  • rowMeans(log_returns)를 사용하여 동일 가중치 지수를 생성합니다.
  • lm()을 사용하여 포트폴리오 수익률을 외부 요인에 회귀 분석합니다(예: lm(Portfolio_Return ~ Factor1 + Factor2)).

출력 요구 사항

  • 선택된 자산 목록을 CSV로 내보냅니다.
  • extractWeights를 사용하여 요약 통계 및 포트폴리오 가중치를 출력합니다.
  • 라이브러리를 로드하고, 수익률 매트릭스를 준비하며, 포트폴리오 사양을 정의하고, 제약 조건을 추가하며, 최적화를 실행하고, 결과를 추출하는 명확하고 실행 가능한 R 코드 청크를 제공합니다.

안티 패턴

  • 입력 데이터에 제공되지 않은 자산 카테고리나 특정 자산 이름을 임의로 생성하지 마십시오.
  • 상품 및 외환 자산에 대한 제약 조건 검사를 건너뛰지 마십시오.
  • 데이터프레임으로 변환하지 않고 매트릭스 객체에 dplyr::select를 사용하지 마십시오.
  • 로그 수익률 계산의 첫 번째 행에서 생성된 NA 값을 처리하는 것을 잊지 마십시오.
  • GMVP 및 Tangency 포트폴리오에 대해 "ROI" 이외의 최적화 방법을 사용하지 마십시오.
  • Tangency 포트폴리오에 box 제약 조건을 추가하지 마십시오.

트리거

  • R에서 포트폴리오 분석 수행
  • GMVP 및 Tangency를 사용한 포트폴리오 가중치 최적화
  • 보상-위험비 기반 자산 선택
  • R에서 요인에 대한 포트폴리오 수익률 회귀 분석
  • PortfolioAnalytics를 사용한 포트폴리오 최적화

Individual skills in this repo

This repo contains 18 individual skills — each has its own dedicated page.

gabrielmoreira/agent-skills-mirror

Design exclusive bonus packages that make YOUR affiliate link the obvious choice. Triggers on: "create bonuses for", "bonus stack", "what bonuses should I offer", "bonus ideas for", "exclusive bonuses", "differentiate my affiliate link", "why buy through my link", "affiliate bonuses", "bonus package", "what can I offer as a bonus", "design bonuses", "build a bonus stack".

gabrielmoreira/agent-skills-mirror

Design irresistible affiliate offers using the Hormozi Grand Slam framework. Triggers on: "create an offer for", "design my offer", "grand slam offer", "make an irresistible offer", "why should someone buy through my link", "offer framework", "value proposition for", "Hormozi offer", "offer stack", "make my offer irresistible", "craft an offer", "what makes my offer different", "offer design", "increase perceived value".

gabrielmoreira/agent-skills-mirror

Create YOUR personal guarantee on top of the product's guarantee for risk reversal. Triggers on: "create a guarantee", "guarantee for my affiliate", "risk reversal", "money back guarantee", "what guarantee can I offer", "reduce buyer risk", "guarantee copy", "how to guarantee", "affiliate guarantee", "personal guarantee", "risk-free offer", "satisfaction guarantee", "results guarantee".

gabrielmoreira/agent-skills-mirror

Build high-converting affiliate landing pages as single self-contained HTML files. Triggers on: "create a landing page for", "build a landing page", "product landing page", "affiliate landing page", "comparison page for", "vs page", "single product page", "conversion page", "sales page for affiliate", "landing page HTML", "build me a page for", "create a page to promote [product]", "I need a landing page", "make a page for [product]".

gabrielmoreira/agent-skills-mirror

Build a single-product deep-dive showcase page as a self-contained HTML file. Triggers on: "build a product showcase page", "deep dive landing page for [product]", "create a product spotlight page", "product feature page", "single product page", "detailed page about [product]", "build a page showing everything about [product]", "create a long-form product page", "build a sales page for [product]", "product deep dive page", "make a feature breakdown page for [product]".

gabrielmoreira/agent-skills-mirror

Build email capture landing pages (squeeze pages) as single self-contained HTML files. Triggers on: "build a squeeze page", "email capture page", "lead magnet page", "create an opt-in page", "build an email list page", "lead capture landing page", "create a freebie page", "build a page to collect emails", "opt-in landing page", "email signup page for [product/niche]", "create a lead magnet landing page", "build a page that captures emails before sending to affiliate offer".

gabrielmoreira/agent-skills-mirror

Design the complete free-to-premium value ladder for affiliate promotions. Triggers on: "value ladder", "customer journey", "upsell path", "ascension model", "free to paid funnel", "tripwire offer", "upsell strategy", "downsell", "product ladder", "price ladder", "customer ascension", "funnel architecture", "map my funnel", "design my funnel stages", "monetization path".

gabrielmoreira/agent-skills-mirror

Build a webinar or live event registration page as a self-contained HTML file with countdown timer, speaker bio, agenda, and registration form. Triggers on: "build a webinar registration page", "create a webinar sign-up page", "event registration landing page", "live training registration page", "workshop sign-up page", "create a webinar page", "build an event page", "free webinar landing page", "live demo registration page", "online event page", "create a registration page for my webinar", "build a training event page".

gabrielmoreira/agent-skills-mirror

Audit paid-ad landing pages for message match, mobile experience, performance, accessibility, trust, forms, consent, tracking, security, and conversion friction. Use for landing-page audit, post-click experience, LP audit, conversion-rate optimization, form optimization, ad-to-page message match, redirects, blocked navigation, or requests involving private, loopback, link-local, or metadata IP destinations.

gabrielmoreira/agent-skills-mirror

Automate Klipfolio tasks via Rube MCP (Composio). Always search tools first for current schemas.

gabrielmoreira/agent-skills-mirror

Review UI code for Web Interface Guidelines compliance.

gabrielmoreira/agent-skills-mirror

Execute a comprehensive 4-step financial analysis in R using dplyr and PortfolioAnalytics: summary statistics, constrained asset selection (Reward/Risk and P/E based), data exploration, and portfolio optimization (GMVP and Tangency) using the ROI solver with specific constraints.

gabrielmoreira/agent-skills-mirror

Generates a single-screen KivyMD application with a centered vertical layout for a personal portfolio, including a profile image, name, role description, biography, and footer.

gabrielmoreira/agent-skills-mirror

Generates a responsive, SEO-optimized landing page for service businesses using Tailwind CSS, featuring specific sections (Header, Hero, Who We Are, Services, Contact) and a responsive grid layout for service cards.

gabrielmoreira/agent-skills-mirror

Generate and rewrite marketing content for software services and portfolios. Adapts tone from professional agency to customer-centric, handles style mimicry, formatting constraints, and strictly manages perspective (e.g., removing first-person pronouns for portfolio contexts).

gabrielmoreira/agent-skills-mirror

When the user wants to design, deploy, or measure Apple Custom Product Pages (CPP) — the alternate App Store product pages with different screenshots, preview videos, and promo text shown to users coming from specific URLs (typically ad campaigns or social posts). Use when the user mentions "Custom Product Page", "CPP", "alternate product page", "App Store URL variant", "ASA CPP", "campaign-specific landing page", "product page per audience", "App Store Connect CPP", "ppoUrl", "?cpp=" parameter, or "show different screenshots to different ad audiences". For App Store A/B tests on the default page, see ab-test-store-listing. For paid ad campaigns that route to CPPs, see apple-search-ads or ua-campaign.

gabrielmoreira/agent-skills-mirror

Generate complete, deploy-ready landing pages from any repository. Use when creating a homepage for an open-source project, building a project website, converting a README into a marketing page, or standardizing landing pages across multiple repos.

gabrielmoreira/agent-skills-mirror

Shapes job-seeking personal sites: thirty-second hero, outcome-led case studies, hybrid home-plus-project routes, and frictionless contact CTAs, with heavy motion that degrades on mobile. Use for developer, designer, or creative portfolio work. Not a SaaS marketing landing page and not a WebGL engine tutorial.

관련 스킬